package per.jdz;

/**
 * finally语句中没有return，则返回值为try语句或者catch语句的返回值
 * finally语句中有return，则返回值为finally语句的返回值
 */
public class OrderProblem {
    public static void main(String[] args) {
        // System.out.println(add(10, 20));
        System.out.println(test());
    }

    public static int add(int a, int b) {
        try {
            return a + b;
        } catch (Exception e) {
            System.out.println("catch语句块");
        } finally {
            System.out.println("finally语句块");
            return 40;
        }
        // return 0;
    }

    private static int test() {
        int temp = 1;
        try {
            System.out.println("try" + temp);
            int i = 1 / 0;
        } catch (Exception e) {
            ++temp;
            System.out.println("catch" + temp);
            return temp;
        } finally {
            System.out.println("finally" + temp);
            ++temp;
            // return temp;
        }
        // System.out.println("temp = " + temp);
        return temp;
    }
}